﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Softyum.ForexAgent;

namespace Softyum.ForexAgent.Controls
{
    public partial class NewsControl : UserControl
    {
        public NewsControl()
        {
            InitializeComponent();
        }

        private void NewsControl_Load(object sender, EventArgs e)
        {
            // Sites
            InitializeSites();
        }

        private void InitializeSites()
        {
            foreach (var cs in Program.NewsSourceManager.Categories)
            {
                foreach (var page in cs.Pages)
                {
                    if (page.Enabled)
                    {
                        AddSiteTab(page);
                    }
                }
            }

            // select the first page
            if (tabControl.TabCount > 0)
                tabControl.SelectedIndex = 0;
        }

        private void AddSiteTab(Site.WebPage page)
        {
            NewsPage newsListPage = new NewsPage();
            newsListPage.Dock = DockStyle.Fill;
            newsListPage.WebSite = page;
            //
            TabPage tp = new TabPage(page.Title);
            tp.Controls.Add(newsListPage);
            this.tabControl.TabPages.Add(tp);
        }
    }
}
